package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-26 23:11
 **/
public class LeetCode423 {

    public String originalDigits(String s) {
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char temp = s.charAt(i);
            map.put(temp, map.getOrDefault(temp, 0) + 1);
        }

        int[] count = new int[10];
        count[0] = map.getOrDefault('z', 0);
        count[2] = map.getOrDefault('w', 0);
        count[4] = map.getOrDefault('u', 0);
        count[6] = map.getOrDefault('x', 0);
        count[8] = map.getOrDefault('g', 0);
        count[7] = map.getOrDefault('s', 0) - count[6];
        count[5] = map.getOrDefault('v', 0) - count[7];
        count[3] = map.getOrDefault('h', 0) - count[8];
        count[1] = map.getOrDefault('o', 0) - count[0] - count[2] - count[4];
        count[9] = map.getOrDefault('i', 0) - count[8] - count[6] - count[5];

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 10; i++) {
            for (int i1 = 0; i1 < count[i]; i1++) {
                builder.append((char)(i + '0'));
            }
        }
        return builder.toString();
    }

}
